package com.dhkj.circle.utils;

import android.content.Context;
import android.os.Handler;

import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;


/**
 * 管理腾讯QMUI的提示框等其他信息
 * <p>
 * showError，提示错误提示框
 * <p>
 * loadingShow，加载提示框，重新调用则刷新里面内容
 * <p>
 * loadingClose，关闭加载提示框
 * <p>
 * loadingCloseOfSuccess，关闭加载提示框，并返回成功提示框
 * <p>
 * loadingCloseOfError ，关闭提示框，并返回错误信息
 * <p>
 * <p>
 * 时间 2019-07-04
 */
public class QMUIView {

    private static QMUITipDialog loadingDialog;

    public static void showError(Context context, String msg) {
        QMUITipDialog tipDialog = new QMUITipDialog.Builder(context)
                .setIconType(QMUITipDialog.Builder.ICON_TYPE_FAIL)
                .setTipWord(msg)
                .create();
        tipDialog.show();
        new Handler().postDelayed(tipDialog::dismiss, 1500);
    }

    public static void showError(Context context, String msg, Long longs) {
        QMUITipDialog tipDialog = new QMUITipDialog.Builder(context)
                .setIconType(QMUITipDialog.Builder.ICON_TYPE_FAIL)
                .setTipWord(msg)
                .create();
        tipDialog.show();
        new Handler().postDelayed(tipDialog::dismiss, longs);
    }

    public static void showSuccess(Context context, String msg) {
        QMUITipDialog tipDialog = new QMUITipDialog.Builder(context)
                .setIconType(QMUITipDialog.Builder.ICON_TYPE_SUCCESS)
                .setTipWord(msg)
                .create();
        tipDialog.show();
        new Handler().postDelayed(tipDialog::dismiss, 1500);
    }

    public static void showSuccess(Context context, String msg, Long longs) {
        QMUITipDialog tipDialog = new QMUITipDialog.Builder(context)
                .setIconType(QMUITipDialog.Builder.ICON_TYPE_SUCCESS)
                .setTipWord(msg)
                .create();
        tipDialog.show();
        new Handler().postDelayed(tipDialog::dismiss, longs);
    }

    public static void loadingShow(Context context, String msg) {
        loadingClose();
        loadingDialog = new QMUITipDialog.Builder(context)
                .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING)
                .setTipWord(msg)
                .create();
        loadingDialog.show();
    }

    public static void loadingClose() {
        if (loadingDialog != null && loadingDialog.isShowing()) {
            //如果提示框正在显示中，则关闭显示框
            loadingDialog.dismiss();
        }
    }

    public static void loadingCloseOfSuccess(Context context, String msg) {
        loadingClose();//检查是否有关闭
        showSuccess(context, msg);
    }

    public static void loadingCloseOfError(Context context, String msg) {
        loadingClose();//检查是否有关闭
        showError(context, msg);
    }
}
